<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <title>常用意见设置</title>
    <link rel="stylesheet" href="/css/workflow/work/automaticNumbering.css">
    <link rel="stylesheet" type="text/css" href="/css/commonTheme/${sessionScope.InterfaceModel}/commonTheme.css"/>
    <script>

        function getCookie(name) {
            var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
            if (arr = document.cookie.match(reg))
                return unescape(arr[2]);
            else
                return null;
        }

        var oHead = document.getElementsByTagName('HEAD').item(0);

        var oScript = document.createElement("script");
        var type = getCookie("language");
        oScript.type = "text/javascript";

        if (type) {
            oScript.src = "/js/Internationalization/" + type + ".js";
        } else {
            oScript.src = "/js/Internationalization/zh_CN.js";
        }
        oHead.appendChild(oScript);

    </script>
    <script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/lib/layer/layer.js?20201106"></script>
    <script type="text/javascript" src="/js/base/base.js"></script>
    <script type="text/javascript" src="/lib/jquery.form.min.js"></script>
    <style>
        .newsBtn {
            padding: 0px 22px 0px 32px;
        }

        .inputlayout {
            height: auto;
            margin-top: 35px;
        }
    </style>
</head>
<body>
<div class="maintop clearfix" style="border-bottom: 1px solid #9E9E9E">
    <p style="margin-left:10px;">
        <img src="/img/commonTheme/${sessionScope.InterfaceModel}/bianhaos.png"
             style="width: 25px;height: 24px;vertical-align: text-bottom;" alt="">
        <label style=" font-size: 22px !important; color: #333333;">常用意见设置</label>
    </p>
    <a class="newsBtn newsBtntwo" data-num="0" style="float: right;margin-right: 3%;margin-top: 5px;"
       href="javascript:void (0)"><img style="margin-right: 4px;margin-left: -10px;margin-bottom: -1px;"
                                       src="../../img/mywork/newbuildworjk.png" alt=""><fmt:message
            code="global.lang.new"/></a>
</div>
<div class="mainBottom" style="margin-top: 19px;">
    <table>
        <thead>
        <tr>
            <th class="th" width="6%" align="center">排序号</th>
            <th class="th" width="45%" align="left" style="text-align: left">意见模板内容</th>
            <th class="th" width="20%" align="center">所属人</th>
            <th class="th" width="15%" align="center">意见类型</th>
            <th class="th" width="14%" align="center"><fmt:message code="menuSSetting.th.menuSetting"/></th>
            <%--操作--%>
        </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
</div>
</body>
<script type="text/javascript">

    // 加载表格数据
    function ajaxdata() {
        var str = ''
        $.get('/flowOpinion/selectAllFlowOpinion', function (json) {
            var arr = json.object;
            for (var i = 0; i < arr.length; i++) {
                var opinionTypeStr = '';
                if (arr[i].opinionType == 0) {
                    opinionTypeStr = '公共意见';
                } else if (arr[i].opinionType == 1) {
                    opinionTypeStr = '个人意见';
                }
                str += '<tr>' +
                    '<td>' + arr[i].opinionId + '<input type="hidden" value="' + arr[i].opinionId + '"></td>' +
                    '<td style="text-align: left">' + arr[i].opinionContent + '</td>' +
                    '<td data-createuser="'+ arr[i].createUser +'">' + arr[i].createUserName + '</td>' +
                    '<td data-opiniontype="'+ arr[i].opinionType +'">' + opinionTypeStr + '</td>' +
                    '<td>' +
                    '<a href="javascript:void (0)" class="newsBtntwo" data-num="1">' + edit1 + '</a>' +
                    '<a href="javascript:void (0)" class="delete">' + del + ' <input type="hidden" value="' + arr[i].opinionId + '"></a>' +
                    '</td>' +
                    '</tr>'
            }
            $('.mainBottom table tbody').html(str)
        }, 'json')
    }

    $(function () {

        ajaxdata();

        // 删除
        $('.mainBottom').delegate('.delete', 'click', function () {
            var me = this;
            $.layerConfirm({title: queding, content: qued, icon: 0}, function () {
                $.post('/flowOpinion/delFlowOpinion',
                    {'opinionId': $(me).parent().parent().find('td').eq(0).find('[type="hidden"]').val()},
                    function (json) {
                        if (json.flag) {
                            $.layerMsg({content: delc, icon: 1}, function () {
                                ajaxdata()
                            });
                        } else {
                            $.layerMsg({content: json.msg, icon: 2})
                        }
                    }, 'json')
            })

        });

        // 新建、编辑
        $(document).delegate('.newsBtntwo', 'click', function () {

            var title = '';
            var url = '';
            var opinionIdStr = '';
            var obj = {};
            var opinionTypeDom = '<input type="radio" name="opinionType" style="margin-right: 5px;" value="0" checked>公共<input type="radio" name="opinionType" style="margin-right: 5px;" value="1">个人'
            if ($(this).attr('data-num') == 0) {
                title = '新建常用意见';
                obj.opinionContent = '';
                obj.opinionType = '';
                url = '/flowOpinion/insertFlowOpinion';
            } else if ($(this).attr('data-num') == 1) {
                title = '编辑常用意见';
                url = '/flowOpinion/updateFlowOpinionById';
                obj.opinionId = parseInt($(this).parent().parent().find('td').eq(0).find('[type="hidden"]').val());
                obj.opinionContent = $(this).parent().parent().find('td').eq(1).text();
                obj.createUser = $(this).parent().parent().find('td').eq(2).data('createuser');
                obj.opinionType = $(this).parent().parent().find('td').eq(3).data('opiniontype');
                if (obj.opinionType == 1) {
                    opinionTypeDom = '<input type="radio" name="opinionType" style="margin-right: 5px;" value="0">公共<input type="radio" name="opinionType" style="margin-right: 5px;" value="1" checked>个人'
                }
                opinionIdStr = '<input type="hidden" name="opinionId" value="' + obj.opinionId + '"><input type="hidden" name="createUser" value="' + obj.createUser + '">'
            }
            layer.open({
                title: title,
                area: ['600px', '400px'],
                type: 1,
                content: '<form id="saveRule" action="' + url + '">'+opinionIdStr+'<div class="inputlayout">' +
                    '<ul>' +
                    '<li class="clearfix">' +
                    '<label>意见模板内容  ：</label><textarea name="opinionContent" rows="3">'+ obj.opinionContent +'</textarea>' +
                    '</li>' +
                    '<li class="clearfix">' +
                    '<label> 意见类型  ：</label>' + opinionTypeDom +
                    '</li>' +
                    '</ul>' +
                    '</div></form>',
                btn: [sure, cancel],
                yes: function (index) {
                    $("#saveRule input[name=code]").css("border-color", "#2f8fed");
                    $('#saveRule').ajaxSubmit({
                        type: 'post',
                        dataType: 'json',
                        success: function (json) {
                            if (json.flag) {
                                $.layerMsg({content: save, icon: 1}, function () {
                                    location.reload();
                                })
                            } else {
                                $.layerMsg({content: json.msg, icon: 2})
                            }
                        }
                    })
                }
            })
        })
    })
</script>
</html>
